package com.example.cloudmaps;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class MapSQLiteHelper extends SQLiteOpenHelper{
	private static final String DATABASE_NAME = "maps.db";
	private static final int DATABASE_VERSION = 1;
	
	public static final String TABLE_USERS = "users";
	
	public static final String COLUMN_USER_ID = "uid";
	public static final String COLUMN_USER = "username";
	public static final String COLUMN_PASSWORD = "password";
	
	private static final String DATABASE_CREATE = "CREATE TABLE " + TABLE_USERS + "(" + 
			COLUMN_USER_ID + " INTEGER PRIMARY KEY AUTOINCREMENT," +
			COLUMN_USER + " VARCHAR, " +
			COLUMN_PASSWORD + " VARCHAR)";
	
	private static final String INSERT_DEFAULT_USER = "INSERT INTO users (uid,username,password) VALUES (1,'user','pass')";
	
	public MapSQLiteHelper(Context context){
		super(context, DATABASE_NAME, null, DATABASE_VERSION);
	}
	
	@Override
	 public void onCreate(SQLiteDatabase database) {
	    database.execSQL(DATABASE_CREATE);
	    database.execSQL(INSERT_DEFAULT_USER);
	  }
	
	@Override
	  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
	    Log.w(MapSQLiteHelper.class.getName(),
	        "Upgrading database from version " + oldVersion + " to "
	            + newVersion + ", which will destroy all old data");
	    db.execSQL("DROP TABLE IF EXISTS " + TABLE_USERS);
	    onCreate(db);
	  }
	
	
}
